<template>
  <span class="checkbox">
    <x-icon
      type="ios-checkmark-empty"
      size="30"
      :class="{ active: value }"
      class="content"
    ></x-icon>

    <input
      class="input"
      @change="handleChange"
      :checked="value"
      :disabled="disabled"
      type="checkbox"
    />
  </span>
</template>

<script>
export default {
  name: "d_checkbox",
  props: {
    disabled: {
      type: Boolean,
      default: false,
    },
    value: {
      type: Boolean,
    },
  },
  methods: {
    handleChange(e) {
      console.log("e", e.target.value, e.target.checked);
      this.$emit("input", e.target.checked);
    },
  },
};
</script>

<style lang="less" scoped>
.checkbox {
  position: relative;
  display: inline-block;
  width: 0.35rem;
  height: 0.35rem;
  border: 1px solid #ccc;
  border-radius: 3px;
  overflow: hidden;
  .content {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);

    z-index: 9;
  }
  .active {
    background-color: #2d8cf0;
  }
  .input {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    z-index: 10;
  }
}
</style>